/**
 * Created by smp on 2017/4/14.
 */
var modelPath=ROOT_PATH+'/observation/statisticsAnalysis/';
var act=CONSTANT.DictionaryTypeDefConstants.UNSAFE_ACT;//不安全行为
function toDate(){
    var date=new Date();
    var year=date.getFullYear();
    var month=date.getMonth()+1;
    if(month<10)
        month="0"+month;
    var day=date.getDate();
    if(day<10)
        day="0"+day;
    return year+"-"+month+"-"+day;
}
$(function () {
    var ate=new Date();
    $("#beginTime").datebox('setValue', ate.getFullYear()+"-01-01");
    $("#endTime").datebox('setValue', toDate());
    var DEPTIdIFNULL=null;
    //初始化组织结构树
    $('#department_tree').tree({
        url: ROOT_PATH + '/permission/department/getDepartmentTree.shtml?parentId=0',
        lines:true,
        onSelect: function (node) {
            //$('#tb1').form('reset');
            //重新按部门加载datagrid
            $('#dg1').datagrid('load', {
                deptId: node.id,
                beginTime:$("#beginTime").datebox('getValue'),
                endTime:$("#endTime").datebox('getValue'),
                dictionaryTypeCode:act
            });
        },
        onLoadSuccess: function (node, data) {
            var deptId = data[0].id;
            DEPTIdIFNULL=deptId;
            //初始化加载datagrid
            $('#dg1').datagrid({
                method: 'post',
                url: modelPath + 'actList.shtml',
                queryParams: {
                    deptId: deptId,
                    beginTime:$("#beginTime").datebox('getValue'),
                    endTime:$("#endTime").datebox('getValue'),
                    dictionaryTypeCode:act
                },
                toolbar:'#tb1',
                //idField: 'id',
                fitColumns: true,
                pagination: false,
                rownumbers: true,
                sortOrder: true,
                striped: true,
                singleSelect:true,
                fit: true,
                columns: [[
                    {field: 'name', title: '不安全行为', width: 100,  sortable: true},
                    {field: 'num', title: '合计', width: 80,  sortable: true}
                ]]
            });
        }
    });
    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
    });
    $('#btn_search').on("click", function () {
        var getSelected = $("#department_tree").tree('getSelected');
        var deptId=DEPTIdIFNULL;
        if(getSelected){
            deptId=getSelected.id
        }
        $('#dg1').datagrid('load', {deptId:deptId,beginTime:$("#beginTime").datebox('getValue'),
            endTime:$("#endTime").datebox('getValue'),
            dictionaryTypeCode:act});
    });
});